package com.forehope.portal.controller;

import com.actionsoft.bpms.bo.design.model.BOModel;
import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.bpmn.engine.cache.HistoryTaskInstanceCache;
import com.actionsoft.bpms.bpmn.engine.cache.ProcessDefCache;
import com.actionsoft.bpms.bpmn.engine.cache.ProcessInstanceCache;
import com.actionsoft.bpms.bpmn.engine.model.run.ProcessInstanceModel;
import com.actionsoft.bpms.bpmn.engine.model.run.delegate.ProcessInstance;
import com.actionsoft.bpms.commons.database.RowMap;
import com.actionsoft.bpms.commons.formfile.model.delegate.FormFile;
import com.actionsoft.bpms.commons.htmlframework.HtmlPageTemplate;
import com.actionsoft.bpms.commons.mvc.view.ResponseObject;
import com.actionsoft.bpms.org.model.DepartmentModel;
import com.actionsoft.bpms.org.model.UserModel;
import com.actionsoft.bpms.server.RequestParams;
import com.actionsoft.bpms.server.SSOUtil;
import com.actionsoft.bpms.server.UserContext;
import com.actionsoft.bpms.server.bind.annotation.Controller;
import com.actionsoft.bpms.server.bind.annotation.Mapping;
import com.actionsoft.bpms.server.fs.DCContext;
import com.actionsoft.bpms.server.fs.dc.DCConst;
import com.actionsoft.bpms.server.fs.dc.DCProfileManager;
import com.actionsoft.bpms.util.DBSql;
import com.actionsoft.sdk.local.SDK;
import com.actionsoft.sdk.local.api.cc.http.Response;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.forehope.portal.aslpUtil.CMSUtil;
import com.forehope.portal.model.NavModel;
import jodd.util.StringUtil;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

@Controller
public class PortalGrounpController {

    /**
     * 刷新页面
     */
    @Mapping(value = "portal.hxcs")
    public String returnHtml(UserContext me) {
        Map<String, Object> macroLibraries = new LinkedHashMap<String, Object>();
        macroLibraries.put("sid", me.getSessionId());
        return HtmlPageTemplate.merge("com.awspaas.user.apps.forehope.portal", "index.html", macroLibraries);
    }

    /**
     * 移动端查看PC表单
     */
    @Mapping(value = "portal.pcformobile")
    public String pcForMobile(UserContext me, String processInstId, String taskInstId, int openState) {
        SDK.getFormAPI().getFormSysButtonsJSON(me,processInstId,taskInstId,SDK.getTaskAPI().getInstanceById(taskInstId).getActivityDefId(),openState);
        SDK.getFormAPI().getFormExtendsButtonsJSON(me,processInstId,taskInstId,SDK.getTaskAPI().getInstanceById(taskInstId).getActivityDefId());

        /**
         * 获取PCSID
         */
        Map<String, Object> macroLibraries = new LinkedHashMap<String, Object>();
        String result = SDK.getFormAPI().getFormPage(me, processInstId, taskInstId, openState, 1, null, null);
        result = result.replace("aws-form-main-toolbar Noprint", "aws-form-main-toolbar-bottom Noprint");
        result = result.replace("</body>", "<link href=\"../apps/com.awspaas.user.apps.forehope.portal/css/pcmobile.css\" rel=\"stylesheet\"> \n  <script type=\"text/javascript\" src=\"../apps/com.awspaas.user.apps.forehope.portal/js/pcmobile.js\"></script> \n</body>");
        result = result.replace("<head>","<head> <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=yes\">");
        macroLibraries.put("CONTENT", result);
//        return HtmlPageTemplate.merge("com.awspaas.user.apps.forehope.portal", "1.html", macroLibraries);
        return HtmlPageTemplate.merge("com.awspaas.user.apps.forehope.portal", "pcmobile.html", macroLibraries);
    }

    /**
     * 获取导航数据
     */
    @Mapping(value = "portal.getnav")
    public ResponseObject getNav(UserContext userContext, String name) {
        ResponseObject responseObject = ResponseObject.newOkResponse("查询成功");
        try {
            PortalGroupUtli portalGroupUtli = new PortalGroupUtli();
            List<NavModel> returnList = new ArrayList<>();
            JSONArray tree = SDK.getPortalAPI().queryNavTree(userContext);
            int orderNum = 0;
            for (int i = 0; i < tree.size(); i++) {
                JSONObject jsonObject = tree.getJSONObject(i);
                NavModel navModel1 = portalGroupUtli.setNavModelData(jsonObject);
                navModel1.setParent("");
                navModel1.setOrderNum(orderNum);
                navModel1.setType(jsonObject.getString("name"));
                orderNum = orderNum + 1;
                returnList.add(navModel1);
                JSONArray directory = jsonObject.getJSONArray("directory");
                for (int j = 0; j < directory.size(); j++) {
                    JSONObject jsonObjectChild = directory.getJSONObject(j);
                    NavModel navModel2 = portalGroupUtli.setNavModelData(jsonObjectChild);
                    navModel2.setParent(jsonObjectChild.getString("id"));
                    navModel2.setName(jsonObject.getString("name") + "/" + jsonObjectChild.getString("name"));
                    navModel2.setOrderNum(orderNum);
                    navModel2.setType(jsonObject.getString("name"));
                    orderNum = orderNum + 1;
                    returnList.add(navModel2);
                    JSONArray function = jsonObjectChild.getJSONArray("function");
                    for (int k = 0; k < function.size(); k++) {
                        JSONObject jsonObjectChild_Child = function.getJSONObject(k);
                        NavModel navModel3 = portalGroupUtli.setNavModelData(jsonObjectChild_Child);
                        navModel3.setParent(jsonObjectChild_Child.getString("id"));
                        navModel3.setName(jsonObject.getString("name") + "/" + jsonObjectChild.getString("name") + "/" + jsonObjectChild_Child.getString("name"));
                        navModel3.setOrderNum(orderNum);
                        navModel3.setType(jsonObject.getString("name"));
                        orderNum = orderNum + 1;
                        returnList.add(navModel3);
                    }
                }
            }
            /**
             * 筛选url为/的数据
             */
            List<NavModel> result = returnList.stream().filter(navModel -> StringUtil.isNotEmpty(navModel.getUrl()) && !navModel.getUrl().equals("/") && navModel.getName().contains(name)).collect(Collectors.toList());

            /**
             * 排序处理
             */
            // 使用 Comparator 比较器排序
            // 使用匿名比较器排序
            Collections.sort(result, new Comparator<NavModel>() {
                @Override
                public int compare(NavModel p1, NavModel p2) {
                    return p1.getOrderNum() - p2.getOrderNum();
                }
            });

            responseObject.setData(result);
        } catch (Exception e) {
            e.printStackTrace();
            responseObject = ResponseObject.newErrResponse("查询失败！");
        } finally {
            return responseObject;
        }
    }


    /**
     * 门户切换
     *
     * @param userContext
     * @param nowPage
     */
    @Mapping(value = "portal.switching")
    public ResponseObject switching(UserContext userContext, String nowPage) {
        ResponseObject responseObject = ResponseObject.newOkResponse("操作成功");
        try {
            BO bo = SDK.getBOAPI().query("BO_EU_PORTAL_TYPE").addQuery("USERID=", userContext.getUID()).detail();
            bo.set("PORTALTYPE", nowPage);
            SDK.getBOAPI().update("BO_EU_PORTAL_TYPE", bo);
        } catch (Exception e) {
            e.printStackTrace();
            responseObject = ResponseObject.newErrResponse("操作失败！");
        } finally {
            return responseObject;
        }
    }

    /**
     * 个人信息获取
     */
    @Mapping(value = "portal.getuserinfo")
    public ResponseObject getUserInfo(UserContext userContext) {
        ResponseObject responseObject = ResponseObject.newOkResponse("个人信息获取成功");
        try {
            UserModel nowUserModel = userContext.getUserModel();
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("userName", nowUserModel.getUserName());
            jsonObject.put("usesrId", nowUserModel.getUID());
            String userPhoto = SDK.getPortalAPI().getUserPhoto(userContext, nowUserModel.getUID());
            String downloadURL = SDK.getPortalAPI().getPortalUrl() + "/r/" + userPhoto.replace("./", "").replace("sid=", "sid=" + userContext.getSessionId());
            jsonObject.put("userPhoto", downloadURL);
            //获取门户打开类型
            String opentype = SDK.getAppAPI().getProperty("com.awspaas.user.apps.forehope.portal", "OPENTYPE");
            jsonObject.put("openType", opentype);
            //获取当前人页面类型
//            BO bo = SDK.getBOAPI().query("BO_EU_PORTAL_TYPE").addQuery("USERID=", userContext.getUID()).detail();
//            if (bo == null) {
//                //创建一条新数据
//                jsonObject.put("portalType", "group");
//                BO newBo = new BO();
//                newBo.set("USERID", userContext.getUID());
//                newBo.set("PORTALTYPE", "group");
//                ProcessInstance p = SDK.getProcessAPI().createProcessInstance("obj_4f4bf00d65314669be17ae8f8830c4e6", userContext.getUID(), "初始出个人门户类型");
//                SDK.getBOAPI().create("BO_EU_PORTAL_TYPE", newBo, p, userContext);
//            } else {
////                jsonObject.put("portalType", bo.getString("PORTALTYPE"));
//                jsonObject.put("portalType", bo.getString("PORTALTYPE"));
//            }
            jsonObject.put("portalType", "group");

            responseObject.setData(jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return responseObject;
        }
    }

    /**
     * 退出门户
     */
    @Mapping(value = "portal.logout")
    public ResponseObject forehopeLogOut(UserContext userContext) {
        ResponseObject responseObject = ResponseObject.newOkResponse("操作成功");
        try {
            boolean result = SDK.getPortalAPI().closeSession(userContext.getSessionId());
        } catch (Exception e) {
            e.printStackTrace();
            responseObject = ResponseObject.newErrResponse("操作失败！");
        } finally {
            return responseObject;
        }
    }

    /**
     * 获取默认背景图
     */
    @Mapping(value = "portal.group.getbackground")
    public ResponseObject getBackGround(UserContext userContext) {
        ResponseObject responseObject = ResponseObject.newOkResponse("操作成功");
        try {
            JSONObject jsonObject = new JSONObject();
            String result = SDK.getAppAPI().getProperty("com.awspaas.user.apps.forehope.portal", "BACK_IMG");
            String downloadURL = SDK.getPortalAPI().getPortalUrl() + result.replace("../portal", "");
            jsonObject.put("backgroundPhoto", downloadURL);
            responseObject.setData(jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
            responseObject = ResponseObject.newErrResponse("操作失败！");
        } finally {
            return responseObject;
        }
    }

    /**
     * 获取公司公告
     */
    @Mapping("portal.grounp.notice")
    public ResponseObject getGroupNotice(UserContext userContext, RequestParams requestParams) {
        ResponseObject responseObject = ResponseObject.newOkResponse("操作成功");
        try {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            Date date = new Date();
            String nowDate = simpleDateFormat.format(date);
            PortalGroupUtli portalGroupUtli = new PortalGroupUtli();
            String modelId = SDK.getAppAPI().getProperty("com.awspaas.user.apps.forehope.portal", "JTGG");
            Map<String, Object> resultMap = portalGroupUtli.dueData(userContext, requestParams, modelId);
            int totalNum = (int) resultMap.get("totalNum");
            List<JSONObject> pageList = (List<JSONObject>) resultMap.get("resultData");
            /**
             * 封装数据
             */
            List<JSONObject> returnJsonObject = new ArrayList<>();
            JSONObject returnData = new JSONObject();
            returnData.put("totalNum", totalNum);
            for (JSONObject jsonObject : pageList) {
                String url = SDK.getPortalAPI().getPortalUrl() + "/r/w?sid=" + userContext.getSessionId() + "&cmd=portal.grounp.getcmsinfo&type=公司公告&title=" + jsonObject.getString("msgTitle") + "&messageId=" + jsonObject.getString("id");
                JSONObject returnJson = new JSONObject();
                returnJson.put("title", jsonObject.getString("msgTitle"));
                returnJson.put("publisher", jsonObject.getString("createUser"));
                returnJson.put("signer", "/");
                returnJson.put("dept", jsonObject.getString("departmentName"));
                returnJson.put("releaseTime", jsonObject.getString("releaseTime"));
                //查询是否有数据
                BO bo = SDK.getBOAPI().query("BO_ACT_CMS_CONTENT").addQuery("MESSAGEID = ", jsonObject.getString("id")).detail();
                String fblx= bo.getString("FBLX");
                if ("历史数据补录".equals(fblx)){
                    String ngr = bo.getString("NGR");
                    String ngrbm = bo.getString("NGRBM");
                    String gwzl = bo.getString("GWZL");
                    String sfhtwj=bo.getString("SFHTWJ");
                    String spld = bo.getString("SPLD");
                    String signer = bo.getString("QFR");
                    if (StringUtil.isNotEmpty(ngr)){
                        UserModel userModel = SDK.getORGAPI().getUser(ngr);
                        if (userModel!=null){
                            ngr = userModel.getUserName();
                        }
                    }
                    returnJson.put("publisher", ngr);
                    if (StringUtil.isNotEmpty(ngrbm)){
                        DepartmentModel userModel = SDK.getORGAPI().getDepartmentById(ngrbm);
                        if (userModel!=null){
                            ngrbm = userModel.getName();
                        }
                    }
                    returnJson.put("dept", ngrbm);
                    if (StringUtil.isNotEmpty(signer)){
                        UserModel userModel = SDK.getORGAPI().getUser(signer);
                        if (userModel!=null){
                            signer = userModel.getUserName();
                        }
                    }
                    returnJson.put("signer",signer);

                    returnJson.put("releaseTime", jsonObject.getString("releaseTime"));
                }else{
                    String fromBindid = bo.getString("OUTPROCESSINSTID");
                    try {
                        BO bo1 = SDK.getBOAPI().query("BO_EU_XZFWSQDSP").detailByBindId(fromBindid);
                        if (bo1 != null) {
                            String ngr= bo1.getString("FIELD0003");
                            if (StringUtil.isNotEmpty(ngr)){
                                UserModel userModel = SDK.getORGAPI().getUser(ngr);
                                if (userModel!=null){
                                    ngr = userModel.getUserName();
                                }
                            }
                            returnJson.put("publisher", ngr);


                            String dept= bo1.getString("FIELD0018");
                            if (StringUtil.isNotEmpty(dept)){
                                DepartmentModel userModel = SDK.getORGAPI().getDepartmentById(dept);
                                if (userModel!=null){
                                    dept = userModel.getName();
                                }
                            }
                            returnJson.put("dept", dept);


                            String signer= bo1.getString("FIELD0015");
                            if (StringUtil.isNotEmpty(signer)){
                                UserModel userModel = SDK.getORGAPI().getUser(signer);
                                if (userModel!=null){
                                    signer = userModel.getUserName();
                                }
                            }
                            returnJson.put("signer",signer);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                returnJson.put("openLink", url);
                returnJson.put("isNew", jsonObject.getString("releaseTime").equals(nowDate) ? "1" : "0");
                returnJsonObject.add(returnJson);
            }

            returnData.put("list", returnJsonObject);
            responseObject.setData(returnData);

        } catch (Exception e) {
            e.printStackTrace();
            responseObject = ResponseObject.newErrResponse("查询数据失败！");
        } finally {
            return responseObject;
        }
    }

    /**
     * 获取公司要闻
     */
    @Mapping("portal.grounp.importannews")
    public ResponseObject getGrounpImportannews(UserContext userContext, RequestParams requestParams) {
        ResponseObject responseObject = ResponseObject.newOkResponse("操作成功");
        try {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            Date date = new Date();
            String nowDate = simpleDateFormat.format(date);
            PortalGroupUtli portalGroupUtli = new PortalGroupUtli();
            String modelId = SDK.getAppAPI().getProperty("com.awspaas.user.apps.forehope.portal", "JTYW");
            Map<String, Object> resultMap = portalGroupUtli.dueData(userContext, requestParams, modelId);
            int totalNum = (int) resultMap.get("totalNum");
            List<JSONObject> pageList = (List<JSONObject>) resultMap.get("resultData");
            /**
             * 封装数据
             */
            List<JSONObject> returnJsonObject = new ArrayList<>();
            JSONObject returnData = new JSONObject();
            returnData.put("totalNum", totalNum);
            List<JSONObject> photoUrls = new ArrayList<>();
            BO bo = SDK.getBOAPI().query("BO_EU_PORTAL_PHOTO").addQuery("TYPE='PORTAL_IMPORTANNEWS'", null).detail();
            List<FormFile> files = new ArrayList<>();
            if (bo != null) {
                files = SDK.getBOAPI().getFiles(bo.getId(), "FILE_PHOTOYS");
            }
            int mrFile = 0;

            for (JSONObject jsonObject : pageList) {
                JSONObject gswy = new JSONObject();
                JSONObject returnJson = new JSONObject();
                //来源表单processinstid
                String piid = jsonObject.getString("piid");
                //获取数据
                BO processBo = SDK.getBOAPI().query("BO_ACT_CMS_CONTENT").detailByBindId(piid);
                ProcessInstance processInstance = SDK.getProcessAPI().getInstanceById(piid);
                List<FormFile> queryPicter = SDK.getBOAPI().getFiles(processBo.getId(), "TITLEPIC");

                if (queryPicter == null || queryPicter.size() == 0) {
                    //查询默认图片
                    if (files != null && files.size() > 0 && mrFile < 4) {
                        FormFile file = files.get(mrFile);
                        DCContext fileDc = new DCContext(userContext, DCProfileManager.getDCProfile("com.awspaas.user.apps.forehope.portal", DCConst.REPOSITORY_UI_FILE), "com.awspaas.user.apps.forehope.portal", file.getId(), file.getBoItemName(), file.getFileName());
                        fileDc.getFilePath();
                        String downloadURL = SDK.getPortalAPI().getPortalUrl() + "/r/" + fileDc.getDownloadURL().replace("./", "").replace("sid=", "sid=" + userContext.getSessionId());
                        returnJson.put("photoUrl", downloadURL);
                        gswy.put("portalurl", downloadURL);
                        mrFile = mrFile + 1;
                    }
                } else {
                    FormFile file = queryPicter.get(0);
                    DCContext fileDc = new DCContext(userContext, DCProfileManager.getDCProfile(processInstance.getAppId(), DCConst.REPOSITORY_UI_FILE), processInstance.getAppId(), file.getId(), file.getBoItemName(), file.getFileName());
                    fileDc.getFilePath();
                    String downloadURL = SDK.getPortalAPI().getPortalUrl() + "/r/" + fileDc.getDownloadURL().replace("./", "").replace("sid=", "sid=" + userContext.getSessionId());
                    gswy.put("portalurl", downloadURL);
                    returnJson.put("photoUrl", downloadURL);
                }

                String url = SDK.getPortalAPI().getPortalUrl() + "/r/w?sid=" + userContext.getSessionId() + "&cmd=portal.grounp.getcmsinfo&type=公司要闻&title=" + jsonObject.getString("msgTitle") + "&messageId=" + jsonObject.getString("id");
                returnJson.put("title", jsonObject.getString("msgTitle"));
                gswy.put("title", jsonObject.getString("msgTitle"));
                gswy.put("openurl", url);
                returnJson.put("publisher", jsonObject.getString("createUser"));
                returnJson.put("signer", "/");
                returnJson.put("dept", jsonObject.getString("departmentName"));
                returnJson.put("releaseTime", jsonObject.getString("releaseTime"));
                //查询是否有数据
                BO bo111 = SDK.getBOAPI().query("BO_ACT_CMS_CONTENT").addQuery("MESSAGEID = ", jsonObject.getString("id")).detail();
                String fblx= bo111.getString("FBLX");
                if ("历史数据补录".equals(fblx)){
                    String ngr = bo111.getString("NGR");
                    String ngrbm = bo111.getString("NGRBM");
                    String gwzl = bo111.getString("GWZL");
                    String sfhtwj=bo111.getString("SFHTWJ");
                    String spld = bo111.getString("SPLD");
                    String signer = bo111.getString("QFR");
                    if (StringUtil.isNotEmpty(ngr)){
                        UserModel userModel = SDK.getORGAPI().getUser(ngr);
                        if (userModel!=null){
                            ngr = userModel.getUserName();
                        }
                    }
                    returnJson.put("publisher", ngr);
                    if (StringUtil.isNotEmpty(ngrbm)){
                        DepartmentModel userModel = SDK.getORGAPI().getDepartmentById(ngrbm);
                        if (userModel!=null){
                            ngrbm = userModel.getName();
                        }
                    }
                    returnJson.put("dept", ngrbm);
                    if (StringUtil.isNotEmpty(signer)){
                        UserModel userModel = SDK.getORGAPI().getUser(signer);
                        if (userModel!=null){
                            signer = userModel.getUserName();
                        }
                    }
                    returnJson.put("signer",signer);
                    returnJson.put("releaseTime", jsonObject.getString("releaseTime"));
                }else {
                    String fromBindid = bo111.getString("OUTPROCESSINSTID");
                    try {
                        BO bo1 = SDK.getBOAPI().query("BO_EU_XZFWSQDSP").detailByBindId(fromBindid);
                        if (bo1 != null) {
                            String ngr= bo1.getString("FIELD0003");
                            if (StringUtil.isNotEmpty(ngr)){
                                UserModel userModel = SDK.getORGAPI().getUser(ngr);
                                if (userModel!=null){
                                    ngr = userModel.getUserName();
                                }
                            }
                            returnJson.put("publisher", ngr);


                            String dept= bo1.getString("FIELD0018");
                            if (StringUtil.isNotEmpty(dept)){
                                DepartmentModel userModel = SDK.getORGAPI().getDepartmentById(dept);
                                if (userModel!=null){
                                    dept = userModel.getName();
                                }
                            }
                            returnJson.put("dept", dept);


                            String signer= bo1.getString("FIELD0015");
                            if (StringUtil.isNotEmpty(signer)){
                                UserModel userModel = SDK.getORGAPI().getUser(signer);
                                if (userModel!=null){
                                    signer = userModel.getUserName();
                                }
                            }
                            returnJson.put("signer",signer);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                returnJson.put("openLink", url);
                returnJson.put("isNew", jsonObject.getString("releaseTime").equals(nowDate) ? "1" : "0");
                returnJsonObject.add(returnJson);
                photoUrls.add(gswy);
            }
            returnData.put("photos", photoUrls);
            returnData.put("list", returnJsonObject);
            /**
             * 处理首页展示图片
             */
            responseObject.setData(returnData);

        } catch (Exception e) {
            e.printStackTrace();
            responseObject = ResponseObject.newErrResponse("查询数据失败！");
        } finally {
            return responseObject;
        }
    }


    /**
     * 获取员工风采
     */
    @Mapping("portal.grounp.staffmien")
    public ResponseObject getGrounpStaffmien(UserContext userContext, RequestParams requestParams) {
        ResponseObject responseObject = ResponseObject.newOkResponse("操作成功");
        try {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            Date date = new Date();
            String nowDate = simpleDateFormat.format(date);
            PortalGroupUtli portalGroupUtli = new PortalGroupUtli();
            String modelId = SDK.getAppAPI().getProperty("com.awspaas.user.apps.forehope.portal", "YGFC");
            Map<String, Object> resultMap = portalGroupUtli.dueData(userContext, requestParams, modelId);
            int totalNum = (int) resultMap.get("totalNum");
            List<JSONObject> pageList = (List<JSONObject>) resultMap.get("resultData");
            /**
             * 封装数据
             */
            List<JSONObject> returnJsonObject = new ArrayList<>();
            JSONObject returnData = new JSONObject();
            returnData.put("totalNum", totalNum);
            BO bo = SDK.getBOAPI().query("BO_EU_PORTAL_PHOTO").addQuery("TYPE='PORTAL_STAFFMIEN'", null).detail();
            List<FormFile> files = new ArrayList<>();
            if (bo!=null){
                files = SDK.getBOAPI().getFiles(bo.getId(), "FILE_PHOTOYS");
            }
            int mrFile = 0;
            for (JSONObject jsonObject : pageList) {
                JSONObject returnJson = new JSONObject();
                //来源表单processinstid
                String piid = jsonObject.getString("piid");
                //获取数据
                BO processBo = SDK.getBOAPI().query("BO_ACT_CMS_CONTENT").detailByBindId(piid);
                ProcessInstance processInstance = SDK.getProcessAPI().getInstanceById(piid);
                List<FormFile> queryPicter = SDK.getBOAPI().getFiles(processBo.getId(), "TITLEPIC");

                if (queryPicter == null || queryPicter.size() == 0 && mrFile < 4) {
                    //查询默认图片
                    if (files != null && files.size() > 0) {
                        FormFile file = files.get(mrFile);
                        DCContext fileDc = new DCContext(userContext, DCProfileManager.getDCProfile("com.awspaas.user.apps.forehope.portal", DCConst.REPOSITORY_UI_FILE), "com.awspaas.user.apps.forehope.portal", file.getId(), file.getBoItemName(), file.getFileName());
                        fileDc.getFilePath();
                        String downloadURL = SDK.getPortalAPI().getPortalUrl() + "/r/" + fileDc.getDownloadURL().replace("./", "").replace("sid=", "sid=" + userContext.getSessionId());
                        returnJson.put("photoUrl", downloadURL);
                        mrFile = mrFile + 1;
                    }
                } else {
                    FormFile file = queryPicter.get(0);
                    DCContext fileDc = new DCContext(userContext, DCProfileManager.getDCProfile(processInstance.getAppId(), DCConst.REPOSITORY_UI_FILE), processInstance.getAppId(), file.getId(), file.getBoItemName(), file.getFileName());
                    fileDc.getFilePath();
                    String downloadURL = SDK.getPortalAPI().getPortalUrl() + "/r/" + fileDc.getDownloadURL().replace("./", "").replace("sid=", "sid=" + userContext.getSessionId());
                    returnJson.put("photoUrl", downloadURL);
                }

                String url = SDK.getPortalAPI().getPortalUrl() + "/r/w?sid=" + userContext.getSessionId() + "&cmd=portal.grounp.getcmsinfo&type=员工风采&title=" + jsonObject.getString("msgTitle") + "&messageId=" + jsonObject.getString("id");

                returnJson.put("title", jsonObject.getString("msgTitle"));
                returnJson.put("publisher", jsonObject.getString("createUser"));
                returnJson.put("signer", "/");
                returnJson.put("dept", jsonObject.getString("departmentName"));
                returnJson.put("releaseTime", jsonObject.getString("releaseTime"));
                //查询是否有数据
                BO bo111 = SDK.getBOAPI().query("BO_ACT_CMS_CONTENT").addQuery("MESSAGEID = ", jsonObject.getString("id")).detail();
                String fblx= bo111.getString("FBLX");
                if ("历史数据补录".equals(fblx)){
                    String ngr = bo111.getString("NGR");
                    String ngrbm = bo111.getString("NGRBM");
                    String gwzl = bo111.getString("GWZL");
                    String sfhtwj=bo111.getString("SFHTWJ");
                    String spld = bo111.getString("SPLD");
                    String signer = bo111.getString("QFR");
                    if (StringUtil.isNotEmpty(ngr)){
                        UserModel userModel = SDK.getORGAPI().getUser(ngr);
                        if (userModel!=null){
                            ngr = userModel.getUserName();
                        }
                    }
                    returnJson.put("publisher", ngr);
                    if (StringUtil.isNotEmpty(ngrbm)){
                        DepartmentModel userModel = SDK.getORGAPI().getDepartmentById(ngrbm);
                        if (userModel!=null){
                            ngrbm = userModel.getName();
                        }
                    }
                    returnJson.put("dept", ngrbm);
                    if (StringUtil.isNotEmpty(signer)){
                        UserModel userModel = SDK.getORGAPI().getUser(signer);
                        if (userModel!=null){
                            signer = userModel.getUserName();
                        }
                    }
                    returnJson.put("signer",signer);
                    returnJson.put("releaseTime", jsonObject.getString("releaseTime"));
                }else{
                    String fromBindid = bo111.getString("OUTPROCESSINSTID");
                    try {
                        BO bo1 = SDK.getBOAPI().query("BO_EU_XZFWSQDSP").detailByBindId(fromBindid);
                        if (bo1 != null) {
                            String ngr= bo1.getString("FIELD0003");
                            if (StringUtil.isNotEmpty(ngr)){
                                UserModel userModel = SDK.getORGAPI().getUser(ngr);
                                if (userModel!=null){
                                    ngr = userModel.getUserName();
                                }
                            }
                            returnJson.put("publisher", ngr);


                            String dept= bo1.getString("FIELD0018");
                            if (StringUtil.isNotEmpty(dept)){
                                DepartmentModel userModel = SDK.getORGAPI().getDepartmentById(dept);
                                if (userModel!=null){
                                    dept = userModel.getName();
                                }
                            }
                            returnJson.put("dept", dept);


                            String signer= bo1.getString("FIELD0015");
                            if (StringUtil.isNotEmpty(signer)){
                                UserModel userModel = SDK.getORGAPI().getUser(signer);
                                if (userModel!=null){
                                    signer = userModel.getUserName();
                                }
                            }
                            returnJson.put("signer",signer);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                returnJson.put("openLink", url);
                returnJson.put("isNew", jsonObject.getString("releaseTime").equals(nowDate) ? "1" : "0");
                returnJsonObject.add(returnJson);
            }
            returnData.put("list", returnJsonObject);
            /**
             * 处理首页展示图片
             */
            responseObject.setData(returnData);

        } catch (Exception e) {
            e.printStackTrace();
            responseObject = ResponseObject.newErrResponse("查询数据失败！");
        } finally {
            return responseObject;
        }
    }

    /**
     * 获取党群之窗
     */
    @Mapping("portal.grounp.political")
    public ResponseObject getGrounpPolitical(UserContext userContext, RequestParams requestParams) {
        ResponseObject responseObject = ResponseObject.newOkResponse("操作成功");
        try {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            Date date = new Date();
            String nowDate = simpleDateFormat.format(date);
            PortalGroupUtli portalGroupUtli = new PortalGroupUtli();
            String modelId = SDK.getAppAPI().getProperty("com.awspaas.user.apps.forehope.portal", "DQZC");
            Map<String, Object> resultMap = portalGroupUtli.dueData(userContext, requestParams, modelId);
            int totalNum = (int) resultMap.get("totalNum");
            List<JSONObject> pageList = (List<JSONObject>) resultMap.get("resultData");
            /**
             * 封装数据
             */
            List<JSONObject> returnJsonObject = new ArrayList<>();
            JSONObject returnData = new JSONObject();
            returnData.put("totalNum", totalNum);
            BO bo = SDK.getBOAPI().query("BO_EU_PORTAL_PHOTO").addQuery("TYPE='PORTAL_POLITICAL'", null).detail();
            List<FormFile> files = new ArrayList<>();
            if(bo!=null){
                files =SDK.getBOAPI().getFiles(bo.getId(), "FILE_PHOTOYS");
            }
            int mrFile = 0;
            for (JSONObject jsonObject : pageList) {
                JSONObject returnJson = new JSONObject();
                //来源表单processinstid
                String piid = jsonObject.getString("piid");
                //获取数据
                BO processBo = SDK.getBOAPI().query("BO_ACT_CMS_CONTENT").detailByBindId(piid);
                ProcessInstance processInstance = SDK.getProcessAPI().getInstanceById(piid);
                List<FormFile> queryPicter = SDK.getBOAPI().getFiles(processBo.getId(), "TITLEPIC");

                if (queryPicter == null || queryPicter.size() == 0 && mrFile < 4) {
                    //查询默认图片
                    if (files != null && files.size() > 0) {
                        FormFile file = files.get(mrFile);
                        DCContext fileDc = new DCContext(userContext, DCProfileManager.getDCProfile("com.awspaas.user.apps.forehope.portal", DCConst.REPOSITORY_UI_FILE), "com.awspaas.user.apps.forehope.portal", file.getId(), file.getBoItemName(), file.getFileName());
                        fileDc.getFilePath();
                        String downloadURL = SDK.getPortalAPI().getPortalUrl() + "/r/" + fileDc.getDownloadURL().replace("./", "").replace("sid=", "sid=" + userContext.getSessionId());
                        returnJson.put("photoUrl", downloadURL);
                        mrFile = mrFile + 1;
                    }
                } else {
                    FormFile file = queryPicter.get(0);
                    DCContext fileDc = new DCContext(userContext, DCProfileManager.getDCProfile(processInstance.getAppId(), DCConst.REPOSITORY_UI_FILE), processInstance.getAppId(), file.getId(), file.getBoItemName(), file.getFileName());
                    fileDc.getFilePath();
                    String downloadURL = SDK.getPortalAPI().getPortalUrl() + "/r/" + fileDc.getDownloadURL().replace("./", "").replace("sid=", "sid=" + userContext.getSessionId());
                    returnJson.put("photoUrl", downloadURL);
                }

                String url = SDK.getPortalAPI().getPortalUrl() + "/r/w?sid=" + userContext.getSessionId() + "&cmd=portal.grounp.getcmsinfo&type=党群之窗&title=" + jsonObject.getString("msgTitle") + "&messageId=" + jsonObject.getString("id");

                returnJson.put("title", jsonObject.getString("msgTitle"));
                returnJson.put("publisher", jsonObject.getString("createUser"));
                returnJson.put("signer", "/");
                returnJson.put("dept", jsonObject.getString("departmentName"));
                returnJson.put("releaseTime", jsonObject.getString("releaseTime"));
                //查询是否有数据
                BO bo111 = SDK.getBOAPI().query("BO_ACT_CMS_CONTENT").addQuery("MESSAGEID = ", jsonObject.getString("id")).detail();
                String fblx= bo111.getString("FBLX");
                if ("历史数据补录".equals(fblx)){
                    String ngr = bo111.getString("NGR");
                    String ngrbm = bo111.getString("NGRBM");
                    String gwzl = bo111.getString("GWZL");
                    String sfhtwj=bo111.getString("SFHTWJ");
                    String spld = bo111.getString("SPLD");
                    String signer = bo111.getString("QFR");
                    if (StringUtil.isNotEmpty(ngr)){
                        UserModel userModel = SDK.getORGAPI().getUser(ngr);
                        if (userModel!=null){
                            ngr = userModel.getUserName();
                        }
                    }
                    returnJson.put("publisher", ngr);
                    if (StringUtil.isNotEmpty(ngrbm)){
                        DepartmentModel userModel = SDK.getORGAPI().getDepartmentById(ngrbm);
                        if (userModel!=null){
                            ngrbm = userModel.getName();
                        }
                    }
                    returnJson.put("dept", ngrbm);
                    if (StringUtil.isNotEmpty(signer)){
                        UserModel userModel = SDK.getORGAPI().getUser(signer);
                        if (userModel!=null){
                            signer = userModel.getUserName();
                        }
                    }
                    returnJson.put("signer",signer);
                    returnJson.put("releaseTime", jsonObject.getString("releaseTime"));
                }else{
                    String fromBindid = bo111.getString("OUTPROCESSINSTID");
                    try {
                        BO bo1 = SDK.getBOAPI().query("BO_EU_XZFWSQDSP").detailByBindId(fromBindid);
                        if (bo1 != null) {
                            String ngr= bo1.getString("FIELD0003");
                            if (StringUtil.isNotEmpty(ngr)){
                                UserModel userModel = SDK.getORGAPI().getUser(ngr);
                                if (userModel!=null){
                                    ngr = userModel.getUserName();
                                }
                            }
                            returnJson.put("publisher", ngr);


                            String dept= bo1.getString("FIELD0018");
                            if (StringUtil.isNotEmpty(dept)){
                                DepartmentModel userModel = SDK.getORGAPI().getDepartmentById(dept);
                                if (userModel!=null){
                                    dept = userModel.getName();
                                }
                            }
                            returnJson.put("dept", dept);


                            String signer= bo1.getString("FIELD0015");
                            if (StringUtil.isNotEmpty(signer)){
                                UserModel userModel = SDK.getORGAPI().getUser(signer);
                                if (userModel!=null){
                                    signer = userModel.getUserName();
                                }
                            }
                            returnJson.put("signer",signer);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                returnJson.put("openLink", url);
                returnJson.put("isNew", jsonObject.getString("releaseTime").equals(nowDate) ? "1" : "0");
                returnJsonObject.add(returnJson);
            }
            returnData.put("list", returnJsonObject);
            /**
             * 处理首页展示图片
             */
            responseObject.setData(returnData);

        } catch (Exception e) {
            e.printStackTrace();
            responseObject = ResponseObject.newErrResponse("查询数据失败！");
        } finally {
            return responseObject;
        }
    }


    /**
     * 获取行业电子书
     */
    @Mapping("portal.grounp.ebook")
    public ResponseObject getGrounpEbook(UserContext userContext) {
        ResponseObject responseObject = ResponseObject.newOkResponse("操作成功");
        try {
            List<JSONObject> returnJsonObject = new ArrayList<>();
            List<BO> queryList = SDK.getBOAPI().query("BO_EU_PORTAL_EBOOK").orderBy("ORDERNUM").asc().list();
            for (BO bo1 : queryList) {
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("title", bo1.getString("TITLE"));
                List<FormFile> files = SDK.getBOAPI().getFiles(bo1.getId(), "LOGO");
                if (files != null && files.size() > 0) {
                    FormFile file = files.get(0);
                    DCContext fileDc = new DCContext(userContext, DCProfileManager.getDCProfile("com.awspaas.user.apps.forehope.portal", DCConst.REPOSITORY_UI_FILE), "com.awspaas.user.apps.forehope.portal", file.getId(), file.getBoItemName(), file.getFileName());
                    fileDc.getFilePath();
                    String downloadURL = SDK.getPortalAPI().getPortalUrl() + "/r/" + fileDc.getDownloadURL().replace("./", "").replace("sid=", "sid=" + userContext.getSessionId());
                    jsonObject.put("logo", downloadURL);
                }
                jsonObject.put("openLink", bo1.getString("OPENLINK"));

                jsonObject.put("orderNum", bo1.getString("ORDERNUM"));
                returnJsonObject.add(jsonObject);
            }
            responseObject.setData(returnJsonObject);

        } catch (Exception e) {
            e.printStackTrace();
            responseObject = ResponseObject.newErrResponse("查询数据失败！");
        } finally {
            return responseObject;
        }
    }


    /**
     * 打开链接
     */
    @Mapping("portal.grounp.openlist")
    public String openlist(UserContext userContext, String type) {
        Map<String, Object> macroLibraries = new LinkedHashMap<String, Object>();
        macroLibraries.put("sid", userContext.getSessionId());
        macroLibraries.put("type", type);
        return HtmlPageTemplate.merge("com.awspaas.user.apps.forehope.portal", "list.html", macroLibraries);
    }

    /**
     * 公司日历节假日接口
     */
    @Mapping("portal.grounp.getjtdays")
    public ResponseObject getJtDays(UserContext userContext) {
        ResponseObject responseObject = ResponseObject.newOkResponse("操作成功");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        PortalGroupUtli portalGroupUtli = new PortalGroupUtli();
        Set<String> totalDate = new HashSet<>();
        JSONObject resultJson = new JSONObject();
        try {
            List<BO> list = SDK.getBOAPI().query("BO_ACT_WORKCALENDAR_HOLIDAY").addQuery("WCTYPE in ('2','3')", null).list();
            for (BO bo : list) {
                String amstarttime = bo.getString("AMSTARTTIME");
                Date sDate = simpleDateFormat.parse(amstarttime);
                String pmendtime = bo.getString("PMENDTIME");
                Date eDate = simpleDateFormat.parse(pmendtime);
                totalDate.addAll(portalGroupUtli.getDatesBetween(sDate, eDate));
            }
            resultJson.put("restDays", totalDate);
            responseObject.setData(resultJson);
        } catch (Exception e) {
            e.printStackTrace();
            responseObject = ResponseObject.newErrResponse("操作失败！");
        } finally {
            return responseObject;
        }
    }


    /**
     * 公司日历获取周数
     */
    @Mapping(value = "portal.grounp.getweeks", session = false, noSessionReason = "计算周别，无须session", noSessionEvaluate = "计算周别，无需session")
    public ResponseObject getWeeks(String startDate) {
        ResponseObject responseObject = ResponseObject.newOkResponse("操作成功");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        List<JSONObject> resultJson = new ArrayList<>();
        try {
            /**
             * 获取当前日期的周数
             */

            Date nDate = new Date();
            Calendar nCalendar = Calendar.getInstance();
            if (nCalendar.getFirstDayOfWeek() != Calendar.MONDAY) {
                nCalendar.setFirstDayOfWeek(Calendar.MONDAY);
            }
            nCalendar.setTime(nDate);
            int nowWeek = nCalendar.get(Calendar.WEEK_OF_YEAR);


            //开始周数
            Date sDate = simpleDateFormat.parse(startDate);
            Calendar calendar = Calendar.getInstance();
            if (calendar.getFirstDayOfWeek() != Calendar.MONDAY) {
                calendar.setFirstDayOfWeek(Calendar.MONDAY);
            }
            calendar.setTime(sDate);
            //开始周数
            int startWeek = calendar.get(Calendar.WEEK_OF_YEAR);
            //获取年份
            int year = calendar.get(Calendar.YEAR);

            /**
             * 获取配置
             */
            BO bo = SDK.getBOAPI().query("BO_EU_PORTAL_YXZ").addQuery("YEAR=", String.valueOf(year)).detail();
            String week = "";
            if (bo!=null){
                week = bo.getString("LAST_WEEK");
            }else{
                week = "0";
            }
            int lastWeek = Integer.valueOf(week);
            //周数+6
            for (int i = 0; i < 6; i++) {
                int sendWeek = startWeek + i;
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("week", sendWeek);
                if (nowWeek == sendWeek) {
                    jsonObject.put("isselect", 1);
                } else {
                    jsonObject.put("isselect", 0);
                }
                if (sendWeek==lastWeek){
                    startWeek = 0-i;
                }
                resultJson.add(jsonObject);
            }
            responseObject.setData(resultJson);
        } catch (Exception e) {
            e.printStackTrace();
            responseObject = ResponseObject.newErrResponse("操作失败！");
        } finally {
            return responseObject;
        }
    }


    /**
     * 获取当前节假日
     */
    @Mapping(value = "portal.grounp.getDateName", session = false, noSessionReason = "获取节假日名称，无须session", noSessionEvaluate = "获取节假日名称，无需session")
    public ResponseObject getHolidayName(String startDate) {
        ResponseObject responseObject = ResponseObject.newOkResponse("操作成功");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:s");
        List<JSONObject> resultJson = new ArrayList<>();
        try {
            /**
             * 获取当前日期的周数
             */

            Date nDate = simpleDateFormat.parse(startDate);
            Calendar nCalendar = Calendar.getInstance();
            nCalendar.setTime(nDate);


            List<BO> list = SDK.getBOAPI().query("BO_ACT_WORKCALENDAR_HOLIDAY").list();
            for (int i=0;i<42;i++){
                int year = nCalendar.get(Calendar.YEAR);
                String nowDate = simpleDateFormat.format(nCalendar.getTime());
                List<BO> list1 = list.stream().filter(bo -> {
                    try {
                        return simpleDateFormat.format(simpleDateFormat1.parse(bo.getString("AMSTARTTIME"))).equals(nowDate) && bo.getString("YEAR").equals(String.valueOf(year));
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                    return false;
                }).collect(Collectors.toList());
                if(list1!=null && list1.size()>0){
                    BO bo = list1.get(0);
                    String wcname = bo.getString("WCNAME");
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("date",nowDate);
                    jsonObject.put("name",wcname);
                    resultJson.add(jsonObject);
                }
                nCalendar.add(Calendar.DAY_OF_MONTH, 1);
                System.out.println("--------------data:"+simpleDateFormat.format(nCalendar.getTime()));
            }
            responseObject.setData(resultJson);
        } catch (Exception e) {
            e.printStackTrace();
            responseObject = ResponseObject.newErrResponse("操作失败！");
        } finally {
            return responseObject;
        }
    }


    /**
     * 获取信息详情
     */
    @Mapping(value = "portal.grounp.getcmsinfo")
    public String getInfo(UserContext userContext, String messageId, String type, String title) {
        CMSUtil cmsUtil = new CMSUtil();
        /**
         * 处理阅读数
         */
        cmsUtil.readNum(userContext.getSessionId(),messageId);
        ResponseObject result = cmsUtil.getMessageInfo(userContext, messageId);
        Map<String, Object> macroLibraries = new LinkedHashMap<String, Object>();
        if (result.isOk()) {
            Map dataList = result.getData(Map.class);
            JSONObject list = (JSONObject) dataList.get("message");
            macroLibraries.put("NGR", list.getString("createUser"));
            macroLibraries.put("NGRBM", list.getString("departmentName"));
            macroLibraries.put("GWZL", "/");
            macroLibraries.put("ISHTWJ", "/");
            macroLibraries.put("SPLD", "/");
            macroLibraries.put("QFR", "/");
            //查询是否有数据
            BO bo = SDK.getBOAPI().query("BO_ACT_CMS_CONTENT").addQuery("MESSAGEID = ", messageId).detail();
//            String sql = "update BO_ACT_CMS_CONTENT set READNUM="+(Integer.valueOf(bo.getString("READNUM"))+1)+" where MESSAGEID = '"+messageId+"'";
//            DBSql.update(sql);
//            SDK.getBOAPI().update("BO_ACT_CMS_CONTENT",bo);
//            macroLibraries.put("LLL",(Integer.valueOf(bo.getString("READNUM"))+1));
            macroLibraries.put("LLL",bo.getString("READNUM"));
            String fblx= bo.getString("FBLX");
            if ("历史数据补录".equals(fblx)){
                String ngr = bo.getString("NGR");
                String ngrbm = bo.getString("NGRBM");
                String gwzl = bo.getString("GWZL");
                String sfhtwj=bo.getString("SFHTWJ");
                String spld = bo.getString("SPLD");
                String qfr = bo.getString("QFR");
                if (StringUtil.isNotEmpty(ngr)){
                    UserModel userModel = SDK.getORGAPI().getUser(ngr);
                    if (userModel!=null){
                        ngr = userModel.getUserName();
                    }
                }
                macroLibraries.put("NGR", ngr);
                if (StringUtil.isNotEmpty(ngrbm)){
                    DepartmentModel userModel = SDK.getORGAPI().getDepartmentById(ngrbm);
                    if (userModel!=null){
                        ngrbm = userModel.getName();
                    }
                }
                macroLibraries.put("NGRBM",ngrbm);
                macroLibraries.put("GWZL", gwzl);
                macroLibraries.put("ISHTWJ", sfhtwj);
                if (StringUtil.isNotEmpty(spld)){
                    UserModel userModel = SDK.getORGAPI().getUser(spld);
                    if (userModel!=null){
                        spld = userModel.getUserName();
                    }
                }
                macroLibraries.put("SPLD", spld);
                if (StringUtil.isNotEmpty(qfr)){
                    UserModel userModel = SDK.getORGAPI().getUser(qfr);
                    if (userModel!=null){
                        qfr = userModel.getUserName();
                    }
                }
                macroLibraries.put("QFR", qfr);
                macroLibraries.put("FBSJ", list.getString("createTime"));
            }else{
                String fromBindid = bo.getString("OUTPROCESSINSTID");
                try {
                    BO bo1 = SDK.getBOAPI().query("BO_EU_XZFWSQDSP").detailByBindId(fromBindid);
                    if (bo1 != null) {
                        String ngr= bo1.getString("FIELD0003");
                        if (StringUtil.isNotEmpty(ngr)){
                            UserModel userModel = SDK.getORGAPI().getUser(ngr);
                            if (userModel!=null){
                                ngr = userModel.getUserName();
                            }
                        }
                        macroLibraries.put("NGR", ngr);

                        String ngrbm = bo1.getString("FIELD0018");
                        if (StringUtil.isNotEmpty(ngrbm)){
                            DepartmentModel departmentModel = SDK.getORGAPI().getDepartmentById(ngrbm);
                            if (departmentModel!=null){
                                ngrbm = departmentModel.getName();
                            }
                        }

                        macroLibraries.put("NGRBM",ngrbm);
                        macroLibraries.put("GWZL", bo1.getString("FIELD0009"));
                        macroLibraries.put("ISHTWJ", bo1.getString("FIELD0017"));
                        String spld = bo1.getString("FIELD0012");
                        if (StringUtil.isNotEmpty(spld)){
                            UserModel userModel = SDK.getORGAPI().getUser(spld);
                            if (userModel!=null){
                                spld = userModel.getUserName();
                            }
                        }
                        macroLibraries.put("SPLD", spld);

                        String qfr = bo1.getString("FIELD0015");
                        if (StringUtil.isNotEmpty(qfr)){
                            UserModel userModel = SDK.getORGAPI().getUser(qfr);
                            if (userModel!=null){
                                qfr = userModel.getUserName();
                            }
                        }
                        macroLibraries.put("QFR", qfr);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            macroLibraries.put("info", list.getString("content"));
            macroLibraries.put("FBSJ", list.getString("createTime"));
        }
        macroLibraries.put("title", title);
        macroLibraries.put("type", type);
        if ("公司要闻".equals(type)||"党群之窗".equals(type)||"员工风采".equals(type)) {
            if (title.contains("【") && title.contains("】")) {
                String[] titles = title.split("】");
                macroLibraries.put("title", titles[1]);
                macroLibraries.put("type", titles[0] + "】");
            }
            return HtmlPageTemplate.merge("com.awspaas.user.apps.forehope.portal", "gsyw.html", macroLibraries);
        }
        return HtmlPageTemplate.merge("com.awspaas.user.apps.forehope.portal", "gw.html", macroLibraries);
    }


    /**
     * iframpdf预览页面
     */
    @Mapping(value = "portal.grounp.pdf")
    public String getPdf(UserContext userContext, String bindid) {
        Map<String, Object> macroLibraries = new LinkedHashMap<String, Object>();
        BO bo = SDK.getBOAPI().query("BO_ACT_CMS_CONTENT").detailByBindId(bindid);
        if (bo != null) {
            List<FormFile> files = SDK.getBOAPI().getFiles(bo.getId(), "ATTACHMENT");
            if (files != null && files.size() > 0) {
                FormFile file = files.get(0);
                DCContext fileDc = new DCContext(userContext, DCProfileManager.getDCProfile(file.getAppId(), DCConst.REPOSITORY_UI_FILE), file.getAppId(), file.getId(), file.getBoItemName(), file.getFileName());
                String filePath = fileDc.getFilePath();
                String downloadURL = SDK.getPortalAPI().getPortalUrl() + "/r/" + fileDc.getDownloadURL().replace("./", "").replace("sid=", "sid=" + userContext.getSessionId());
                macroLibraries.put("pdfUrl", downloadURL);
            }
        }
        return HtmlPageTemplate.merge("com.awspaas.user.apps.forehope.portal", "pdf.html", macroLibraries);
    }


    /**
     * 移动端公司门户
     * @param userContext
     * @param bindid
     * @return
     */
    @Mapping(value = "portal.mobilegs")
    public String getMobilegs(UserContext userContext, String bindid) {
        Map<String, Object> macroLibraries = new LinkedHashMap<String, Object>();
        String sid = userContext.getSessionId();
        macroLibraries.put("sid", sid);
        return HtmlPageTemplate.merge("com.awspaas.user.apps.forehope.portal", "mobilegs.html", macroLibraries);
    }



    /**
     * 移动端公司门户
     * @param userContext
     * @return
     */
    @Mapping(value = "portal.mobiletohtml")
    public String mobileToHtml(UserContext userContext, String name) {
        Map<String, Object> macroLibraries = new LinkedHashMap<String, Object>();
        String sid = userContext.getSessionId();
        macroLibraries.put("sid", sid);
        return HtmlPageTemplate.merge("com.awspaas.user.apps.forehope.portal", name, macroLibraries);
    }



}
